﻿Imports System.IO
Public Class frmOutlineWeather

    Private m_heightTierDataConcourse As New HeightTierDataConcourse
   
    ''' <summary>
    ''' 表格显示出数据
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ShowFlexData()
        Dim medate As String = ""
        Me.FlexData.Rows.Count = Me.m_heightTierDataConcourse.ArrHeightTierData.Length + 1

        For i As Integer = 0 To Me.m_heightTierDataConcourse.ArrHeightTierData.Length - 1
            Me.FlexData.SetData(i + 1, 0, i + 1)
            medate = Me.m_heightTierDataConcourse.ArrHeightTierData(i).Year & "-" & Me.m_heightTierDataConcourse.ArrHeightTierData(i).Month & "-" & Me.m_heightTierDataConcourse.ArrHeightTierData(i).Day
            Me.FlexData.SetData(i + 1, 1, medate)

            Me.FlexData.SetData(i + 1, 2, Me.m_heightTierDataConcourse.ArrHeightTierData(i).Time)
            If Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyTierHeight = 9999 Then
            ElseIf Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyTierHeight <> 9999 Then
                Me.FlexData.SetData(i + 1, 3, Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyTierHeight)
            End If

            If Me.m_heightTierDataConcourse.ArrHeightTierData(i).Tiptop = 9 Then
            ElseIf Me.m_heightTierDataConcourse.ArrHeightTierData(i).Tiptop <> 9 Then
                Me.FlexData.SetData(i + 1, 4, Me.m_heightTierDataConcourse.ArrHeightTierData(i).Tiptop)
            End If
            If Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyWindVane = 999 Then
            ElseIf Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyWindVane <> 999 Then
                Me.FlexData.SetData(i + 1, 5, Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyWindVane)
            End If

            If Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyWindSpeed = 99.9 Then
            ElseIf Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyWindSpeed <> 99.9 Then
                Me.FlexData.SetData(i + 1, 6, Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyWindSpeed)
            End If

            If Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyTierTemperature = 99.9 Then
            ElseIf Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyTierTemperature <> 99.9 Then
                Me.FlexData.SetData(i + 1, 7, Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyTierTemperature)
            End If
            If Me.m_heightTierDataConcourse.ArrHeightTierData(i).LevelWindVane = 99 Then
            ElseIf Me.m_heightTierDataConcourse.ArrHeightTierData(i).LevelWindVane <> 99 Then
                Me.FlexData.SetData(i + 1, 8, Me.m_heightTierDataConcourse.ArrHeightTierData(i).LevelWindVane)
            End If
            If Me.m_heightTierDataConcourse.ArrHeightTierData(i).ApeakWindSpeed = 99 Then
            ElseIf Me.m_heightTierDataConcourse.ArrHeightTierData(i).ApeakWindSpeed <> 99 Then
                Me.FlexData.SetData(i + 1, 9, Me.m_heightTierDataConcourse.ArrHeightTierData(i).ApeakWindSpeed)
            End If




        Next

    End Sub
  

   

    Private Sub frmOutlineWeather_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.FlexData.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)

        Me.FlexData.Rows.Count = 1
        Me.FlexData.AutoSizeRows()


        Me.FlexData.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.FlexData.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.FlexData.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
    End Sub

    Private Sub FlexData_AfterEdit(ByVal sender As System.Object, ByVal e As C1.Win.C1FlexGrid.RowColEventArgs) Handles FlexData.AfterEdit
        Dim lrow As Integer = Me.FlexData.RowSel
        Dim lcol As Integer = Me.FlexData.ColSel

        If lrow > 0 Then

            If lcol = 3 Then
                Me.m_heightTierDataConcourse.ArrHeightTierData(lrow - 1).CurrentlyTierHeight = Me.FlexData.GetData(lrow, lcol)
            ElseIf lcol = 4 Then
                Me.m_heightTierDataConcourse.ArrHeightTierData(lrow - 1).Tiptop = Me.FlexData.GetData(lrow, lcol)
            ElseIf lcol = 5 Then
                Me.m_heightTierDataConcourse.ArrHeightTierData(lrow - 1).CurrentlyWindVane = Me.FlexData.GetData(lrow, lcol)
            ElseIf lcol = 6 Then
                Me.m_heightTierDataConcourse.ArrHeightTierData(lrow - 1).CurrentlyWindSpeed = Me.FlexData.GetData(lrow, lcol)
            ElseIf lcol = 7 Then
                Me.m_heightTierDataConcourse.ArrHeightTierData(lrow - 1).CurrentlyTierTemperature = Me.FlexData.GetData(lrow, lcol)
            ElseIf lcol = 8 Then
                Me.m_heightTierDataConcourse.ArrHeightTierData(lrow - 1).LevelWindVane = Me.FlexData.GetData(lrow, lcol)
            ElseIf lcol = 9 Then
                Me.m_heightTierDataConcourse.ArrHeightTierData(lrow - 1).ApeakWindSpeed = Me.FlexData.GetData(lrow, lcol)
            End If
        End If
    End Sub

    Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFile.Click
        Dim f_CurrentlyTierHeight As String = ""
        Dim f_Tiptop As String = ""
        Dim f_CurrentlyWindVane As String = ""
        Dim f_CurrentlyWindSpeed As String = ""
        Dim f_CurrentlyTierTemperature As String = ""
        Dim f_LevelWindVane As String = ""
        Dim f_ApeakWindSpeed As String = ""


        Dim msg As Integer = 0
        Dim msgerror As Boolean = False
        Dim p As Integer = 0
        Dim b As Integer = 0
        Dim Result As DialogResult
        Dim agency As String = ""
        Me.OpenFileDialog1 = New OpenFileDialog()
        OpenFileDialog1.Filter = "高空数据文件(*.PFL)|*.PFL"
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)

            If OpenFileDialog1.FileName <> "" Then

                Do Until EOF(1)
                    Dim strline As String = LineInput(1)
                    msg += 1
                    If msg = 1 Then
                        If StringHandle.FileType(strline) = 4 Then
                            msgerror = True
                        Else
                            msgerror = False
                            Result = MessageBox.Show("你打开的文件格式不正确！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
                            If Result = Windows.Forms.DialogResult.OK Then
                                Exit Do
                            End If
                        End If
                    End If

                    ReDim Preserve m_heightTierDataConcourse.ArrHeightTierData(p)
                    m_heightTierDataConcourse.ArrHeightTierData(p) = New HeightTierData
                    Dim a As Integer = StringHandle.GetString(strline, 1).Trim().Length
                    If StringHandle.GetString(strline, 1).Trim().Length > 2 Then
                        Me.m_heightTierDataConcourse.ArrHeightTierData(p).Year = CInt(StringHandle.GetString(strline, 1))
                    Else
                        If StringHandle.GetString(strline, 1) >= 50 Then
                            Me.m_heightTierDataConcourse.ArrHeightTierData(p).Year = "19" & CInt(StringHandle.GetString(strline, 1))
                        ElseIf StringHandle.GetString(strline, 1) >= 10 Then
                            Me.m_heightTierDataConcourse.ArrHeightTierData(p).Year = "20" & CInt(StringHandle.GetString(strline, 1))
                        ElseIf StringHandle.GetString(strline, 1) >= 0 And StringHandle.GetString(strline, 1) <= 9 Then
                            Me.m_heightTierDataConcourse.ArrHeightTierData(p).Year = "200" & CInt(StringHandle.GetString(strline, 1))
                        End If
                    End If


                    Me.m_heightTierDataConcourse.ArrHeightTierData(p).Month = StringHandle.GetString(strline, 2)
                    Me.m_heightTierDataConcourse.ArrHeightTierData(p).Day = StringHandle.GetString(strline, 3)
                    Me.m_heightTierDataConcourse.ArrHeightTierData(p).Time = StringHandle.GetString(strline, 4)



                    f_CurrentlyTierHeight = Mid(strline, 12, 7)
                    f_Tiptop = Mid(strline, 19, 2)
                    f_CurrentlyWindVane = Mid(strline, 21, 6)
                    f_CurrentlyWindSpeed = Mid(strline, 27, 8)
                    f_CurrentlyTierTemperature = Mid(strline, 35, 8)
                    f_LevelWindVane = Mid(strline, 43, 7)
                    f_ApeakWindSpeed = Mid(strline, 50, 8)


                    Me.m_heightTierDataConcourse.ArrHeightTierData(p).CurrentlyTierHeight = f_CurrentlyTierHeight.Trim()
                    Me.m_heightTierDataConcourse.ArrHeightTierData(p).Tiptop = f_Tiptop.Trim()
                    Me.m_heightTierDataConcourse.ArrHeightTierData(p).CurrentlyWindVane = f_CurrentlyWindVane.Trim()
                    Me.m_heightTierDataConcourse.ArrHeightTierData(p).CurrentlyWindSpeed = f_CurrentlyWindSpeed.Trim()
                    Me.m_heightTierDataConcourse.ArrHeightTierData(p).CurrentlyTierTemperature = f_CurrentlyTierTemperature.Trim()
                    Me.m_heightTierDataConcourse.ArrHeightTierData(p).LevelWindVane = f_LevelWindVane.Trim()
                    Me.m_heightTierDataConcourse.ArrHeightTierData(p).ApeakWindSpeed = f_ApeakWindSpeed.Trim()

                    'Me.m_heightTierDataConcourse.ArrHeightTierData(p).CurrentlyTierHeight = StringHandle.GetString(strline, 5)
                    'Me.m_heightTierDataConcourse.ArrHeightTierData(p).Tiptop = StringHandle.GetString(strline, 6)
                    'Me.m_heightTierDataConcourse.ArrHeightTierData(p).CurrentlyWindVane = StringHandle.GetString(strline, 7)
                    'Me.m_heightTierDataConcourse.ArrHeightTierData(p).CurrentlyWindSpeed = StringHandle.GetString(strline, 8)
                    'Me.m_heightTierDataConcourse.ArrHeightTierData(p).CurrentlyTierTemperature = StringHandle.GetString(strline, 9)
                    'Me.m_heightTierDataConcourse.ArrHeightTierData(p).LevelWindVane = StringHandle.GetString(strline, 10)
                    'Me.m_heightTierDataConcourse.ArrHeightTierData(p).ApeakWindSpeed = StringHandle.GetString(strline, 11)

                    p = p + 1
                Loop
            End If

            FileClose(1)
            If msgerror = True Then
                ShowFlexData()
            End If

        End If
    End Sub

    Private Sub btnSaveFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveFile.Click
        Dim swr As StreamWriter

        Dim year As String = ""
        Dim saveFileDialog1 As New SaveFileDialog()

        saveFileDialog1.Filter = " 高空数据文件(*.PFL)|*.PFL"
        saveFileDialog1.FilterIndex = 2
        saveFileDialog1.RestoreDirectory = True
        saveFileDialog1.InitialDirectory = Application.ExecutablePath
        saveFileDialog1.OverwritePrompt = True
        If saveFileDialog1.ShowDialog() = DialogResult.OK Then

            swr = New StreamWriter(saveFileDialog1.FileName)
            Dim da As String = ""
            For i As Integer = 0 To Me.m_heightTierDataConcourse.ArrHeightTierData.Length - 1
                da = ""
                year = ""
                year = Me.m_heightTierDataConcourse.ArrHeightTierData(i).Year
                da += Mid(year, 3, 2)
                da += Me.m_heightTierDataConcourse.ArrHeightTierData(i).Month.ToString.PadLeft(3)
                da += Me.m_heightTierDataConcourse.ArrHeightTierData(i).Day.ToString.PadLeft(3)
                da += Me.m_heightTierDataConcourse.ArrHeightTierData(i).Time.ToString.PadLeft(3)


                da += Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyTierHeight.ToString.PadLeft(7)
                da += Me.m_heightTierDataConcourse.ArrHeightTierData(i).Tiptop.ToString.PadLeft(2)
                da += Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyWindVane.ToString.PadLeft(6)
                da += Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyWindSpeed.ToString.PadLeft(8)
                da += Me.m_heightTierDataConcourse.ArrHeightTierData(i).CurrentlyTierTemperature.ToString.PadLeft(8)
                da += Me.m_heightTierDataConcourse.ArrHeightTierData(i).LevelWindVane.ToString.PadLeft(7)
                da += Me.m_heightTierDataConcourse.ArrHeightTierData(i).ApeakWindSpeed.ToString.PadLeft(8)

                swr.WriteLine(da)
            Next

            swr.Close()
            swr.Dispose()
        End If
    End Sub

    Private Sub TsbtnSaveFileData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TsbtnOpenFileData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class